package com.ty.config;

import com.ty.servlet.LogFilter;
import com.ty.servlet.ServletRequestListener1;
import com.ty.servlet.SessionListener;
import com.ty.servlet.TestServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ServletConfig {

    //@Bean
    public ServletRegistrationBean testServlet(){
        ServletRegistrationBean bean = new ServletRegistrationBean();
        bean.setServlet(new TestServlet());
        bean.addUrlMappings("/test");
        return bean;
    }
    // @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(new LogFilter());
        bean.addUrlPatterns("/*");
        return bean;
    }
    // @Bean
    public ServletListenerRegistrationBean  servletListenerRegistrationBean(){
        ServletListenerRegistrationBean bean = new ServletListenerRegistrationBean();
        bean.setListener(new SessionListener());
        return bean;
    }
}